#!/bin/sh

# This script will help you to easly create new pages, and don't waste your time
# doing the same thing over and over (create the paths, create the model, the view
# and the controller)

# The first argument is the file name, eg "profile", the second one is the class
# name, eg "Profile".

$(mkdir "../apps/frontend/views/"$1);

#We are gonna to generate the controller

echo 'CONTROLLER >> ../apps/backend/controllers/'$1'.php';

echo '<?php' > ../apps/backend/controllers/$1'.php';
echo '<?php';
echo '\tclass '$2' extends Controller {' >> ../apps/backend/controllers/$1'.php';
echo '\tclass '$2' extends Controller {';
echo '\t\tfunction __construct() {' >> ../apps/backend/controllers/$1'.php';
echo '\t\tfunction __construct() {';
echo '\t\t\tparent::__construct();' >> ../apps/backend/controllers/$1'.php';
echo '\t\t\tparent::__construct();';
echo '\t\t}' >> ../apps/backend/controllers/$1'.php';
echo '\t\t}';
echo '\t\tfunction index() {' >> ../apps/backend/controllers/$1'.php';
echo '\t\tfunction index() {';
echo '\t\t\t$this->view->render("'$1'/index");' >> ../apps/backend/controllers/$1'.php';
echo '\t\t\t$this->view->render("'$1'/index");';
echo '\t\t}' >> ../apps/backend/controllers/$1'.php';
echo '\t\t}';
echo '\t}' >> ../apps/backend/controllers/$1'.php';
echo '\t}';

#We are gonna to generate the model

echo 'MODEL >> ../apps/backend/models/'$1'_model.php';

echo '<?php' > '../apps/backend/models/'$1'_model.php';
echo '<?php';
echo '\tclass '$2'_Model extends Model {' >> '../apps/backend/models/'$1'_model.php';
echo '\tclass '$2'_Model extends Model {';
echo '\t\tfunction __construct() {' >> '../apps/backend/models/'$1'_model.php';
echo '\t\tfunction __construct() {';
echo '\t\t\tparent::__construct();' >> '../apps/backend/models/'$1'_model.php';
echo '\t\t\tparent::__construct();';
echo '\t\t}' >> '../apps/backend/models/'$1'_model.php';
echo '\t\t}';
echo '\t}' >> '../apps/backend/models/'$1'_model.php';
echo '\t}';

#We are gonna to generate the view

echo 'VIEW >> ../apps/frontend/views/'$1'/index.php';

echo '<h1>'$2'</h1>';
echo '<h1>'$2'</h1>' > '../apps/frontend/views/'$1'/index.php';
echo '\t<p>This is the '$2' view.</p>';
echo '\t<p>This is the '$2' view.</p>' >> '../apps/frontend/views/'$1'/index.php';
